import React, { Component,createContext } from 'react'




// 1. 创建一个上下文
const TitleContext = createContext()

class First extends Component {
  render(){
    return (<div>
      First： {this.context.name} -- {this.context.age}
      <Section  />
    </div>)
  }
}
First.contextType = TitleContext

const Section = ()=>{
  return (<div>
    <TitleContext.Consumer>
      {(value)=>{
        
        // 使用数据
        return (<h1>Section: {value.name}</h1>)
      }}
    </TitleContext.Consumer>

    
  </div>)
}

export default class App extends Component {
  render() {
    return (
      <div>
        App

        <TitleContext.Provider value={{name: '高举', age: 18, sex: '女'}}>
          <First  />
        </TitleContext.Provider>
        
      </div>
    )
  }
}
